<?php
class SetorDAO{
	
	private static  $instanciaUnica;
	private $conexao;
	
	private function __construct(){
		$this->conexao = Conexao::getConexao();
	}

	public static function getInstancia(){
		if (!isset(self::$instanciaUnica))
		self::$instanciaUnica = new SetorDAO();
		return self::$instanciaUnica;
	}

	public function lista(){
		$lista	=	Array();
		$rs		=	new QueryMySql();
		$rs->setQuery("Select * From tbl_setor");
		while ($rs->getrow()){
			$s = new Setor();
			$s->setCodSetor($rs->field("codSetor"));
			$s->setDescricao($rs->field("descricao"));
			$lista[] = $ts;
		}
		return $lista;
	}

	public function insertSetor(Setor $Setor){
		$sql 		= new UpdateSQL();
		$sql->setTable("tbl_setor");
		$sql->addField("descricao", $Setor->getDescricao(),"String");
		$sql->setAction("INSERT");
		return $this->conexao->execute($sql->getSQL());
	}

	public function updateSetor(Setor $setor){
		$sql 		= new UpdateSQL();
		$sql->setTable("tbl_setor");
		$sql->setKey("codSetor", $setor->getCodSetor() ,"Number");
		$sql->addField("descricao", $setor->getDescricao(),"String");
		$sql->setAction("UPDATE");
		return $this->conexao->execute($sql->getSQL());
	}

	public function deleteTipoSeguro(Setor $setor){
		//$instituicao = new Instituicao();
		$sql = new UpdateSQL();
		$sql->setTable("tbl_setor");
		$sql->setKey("codSetor", $setor->getCodSetor(), "Number");
		$sql->setAction("DELETE");
		return $this->conexao->executeUpdate($sql->getSQL());
	}
}
?>